package edu.java.ishop.dao.impl;

import java.io.IOException;
import java.util.List;

import javax.inject.Named;

import org.springframework.beans.factory.annotation.Value;

import edu.java.ishop.dao.ProductDao;
import edu.java.ishop.dao.accessors.SocketDatasourceAccessor;
import edu.java.ishop.model.Product;
import edu.java.ishop.model.ProductCategory;
import edu.java.ishop.utils.ApplicationConfiguration;
@Named("socketDao")
public class ProductSocketDao extends SocketDatasourceAccessor implements
		ProductDao {

	public ProductSocketDao() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean save(Product product) {
		throw new UnsupportedOperationException("save(Product)");

	}

	@Override
	public void delete(long Id) {
		throw new UnsupportedOperationException("delete(Long)");
	}

	@Override
	public Product getById(long Id) {
		throw new UnsupportedOperationException("getById(modelId)");
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<Product> getAll() {
		
		try {
			return (List<Product>)sendRequest("getAll");
		} catch (ClassNotFoundException | IOException e) {
			
			//TODO: log
			throw new RuntimeException(e);
		}
	}

	@Override
	public List<Product> getByCategoty(ProductCategory category) {
		throw new UnsupportedOperationException("getByCategoty");
	}

	
	@Value("${socket.host}")
	private String socketHost;
	@Override
	public String getHost() {
		
		return socketHost;
				//ApplicationConfiguration.getItem("socket.host");
	}

	@Value("${socket.port}")
	private String socketPort;
	@Override
	public int getPort() {
		
		return Integer.parseInt(socketPort);
				//Integer.valueOf(ApplicationConfiguration.getItem("socket.port"));
	}

	@Override
	public void delete(Product model) {
		throw new UnsupportedOperationException("delete(Product)");
		
	}

	@Override
	public void update(Product product) {
		// TODO Auto-generated method stub
		
	}

}
